package com.pwser.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pwser.service.UserService;

@RestController
@RequestMapping("/user")
public class UserController {
	@Autowired
	private UserService userService;
	
	@RequestMapping("/findUser")
	public String findUser() {
		userService.findUser();
		return "success";
	}
	
	@RequestMapping("/findUserJPA")
	public String findUserJPA() {
		userService.findUserJPA();
		return "success";
	}
	
	@RequestMapping("/getAllUsersMyBatis")
	public String getAllUsersMyBatis() {
		userService.getAllUsersMyBatis();
		return "success";
	}
	
	@RequestMapping("/findByNameMyBatis")
	public String findByNameMyBatis(String name) {
		userService.findByNameMyBatis(name);
		return "success";
	}
	
	@RequestMapping("/insertMyBatis")
	public String insertMyBatis(Integer id, String name) {
		userService.insertMyBatis(id, name);
		return "success";
	}
	
	@RequestMapping("/getAllUsers")
	public String getAllUsers() {
		userService.getAllUsersTest1();
		userService.getAllUsersTest2();
		return "success";
	}
	
	@RequestMapping("/insertTest1")
	public String insertTest1(Integer id, String name) {
		userService.insertTest1(id, name);
		return "success";
	}
	
	@RequestMapping("/insertTest2")
	public String insertTest2(Integer id, String name) {
		userService.insertTest2(id, name);
		return "success";
	}
	
	@RequestMapping("/insertTest")
	public String insertTest(Integer id, String name) {
		//两个事务分别控制
//		userService.insertTest1(id, name);
//		userService.insertTest2(id, name);
		
		userService.insertTest(id, name);
//		int i = 1 / 0;
		return "success";
	}
	
}
